﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ManipulatingData {
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            
            InitializeComponent();
            NwindDataSet rd=  (NwindDataSet)Resources["set"];
         NwindDataSetTableAdapters.CustomersTableAdapter an = new NwindDataSetTableAdapters.CustomersTableAdapter();
         an.Fill(rd.Customers);
         System.ComponentModel.ICollectionView li= CollectionViewSource.GetDefaultView(rd.Customers);
        
            CollectionViewSource.GetDefaultView(rd.Customers).SortDescriptions.Add(new System.ComponentModel.SortDescription("ContactName",System.ComponentModel.ListSortDirection.Ascending ));
        CollectionViewSource.GetDefaultView(rd.Customers).GroupDescriptions.Add(new PropertyGroupDescription("Country",new GroupConverter()));
        BindingListCollectionView bdcv = (BindingListCollectionView)CollectionViewSource.GetDefaultView(rd.Customers);
      //  bdcv.CustomFilter = "Country = 'Venezuela'";

       
        }
    }

    public class TSelector : DataTemplateSelector {

        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            FrameworkElement e = (FrameworkElement)container;

            System.Data.DataRowView drv = (System.Data.DataRowView)item;

            if (drv["CompanyName"].Equals( "Ana Trujillo Emparedados y helados")) {
                return (DataTemplate) e.FindResource("t1");
            }
          return (DataTemplate)e.FindResource("t2");
        }
    
    }

    public class ColorConverter : IValueConverter {


        object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {

            if (value.ToString().Equals("Ana Trujillo Emparedados y helados")) {
                return new SolidColorBrush(Colors.Green);
            } else {
                return new SolidColorBrush(Colors.Blue);
            }
         
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            throw new NotImplementedException();
        }
    }

    public class GroupConverter : IValueConverter {


        object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {

            if (value.ToString().Equals("Venezuela")) {
                return "VENEZOLANOS";
            } else {
                return "RESTO DEL MUNDO";
            }

        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            throw new NotImplementedException();
        }
    }

}
